﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp6
{
    public partial class Form2 : Form
    {

        private int iD;
        private char  Password;
        private DateTime CReatedTime;

        public Form2()
        {
            InitializeComponent();
        }
        private int id;

        public Form2(string sName, int iD, char  password, DateTime CreatedTime)
        {
            InitializeComponent();
            this.iD = iD;
            textBox1.Text = sName;
            textBox2.Text = password.ToString();
            textBox3.Text = CreatedTime.ToString();
        }
      


        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void Label1_Click(object sender, EventArgs e)
        {

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            var SName = textBox1.Text;
            var Password = textBox2.Text;
            var CReatedTime = textBox3.Text;
            if (this.iD > 0)
            {
                var sql = string.Format("Update Stu1 set SName='{0}',Age={1} ,Grad={2} where iD=3 ", SName, Password, CReatedTime, this.iD);
                DbHelper.AddOrUpdateOrDelete(sql);
                MessageBox.Show("更新成功", "提示");
            }
            else
            {
                var sql = string.Format("insert into Stu1 (SName,Age,Grad) values('{0}',{1},{2})", SName, Password, CReatedTime);
                DbHelper.AddOrUpdateOrDelete(sql);
                MessageBox.Show("添加成功", "提示");
            }
            this.DialogResult = DialogResult.Yes;
            this.Close();

        }
    }
    }
